﻿using Abp.AutoMapper;
using Abp.Dependency;
using Abp.Hangfire;
using Abp.Hangfire.Configuration;
using Abp.Modules;
using Abp.Reflection.Extensions;
using Abp.Runtime.Session;
using Hicap.QRCodeWarehouse.Core.Common;
using Hicap.QRCodeWarehouse.Core.Identity;
using Microsoft.AspNetCore.Mvc.Cors;

namespace Hicap.QRCodeWarehouse.Core
{
    [DependsOn(typeof(AbpHangfireAspNetCoreModule),
        typeof(AbpAutoMapperModule))]
    public class QrCodeWarehouseCoreModule : AbpModule
    {
        public override void Initialize()
        {
            IocManager.RegisterAssemblyByConvention(typeof(QrCodeWarehouseCoreModule).GetAssembly());
        }

        public override void PreInitialize()
        {
            IocManager.Register<HicapAuthorizationFilter>(DependencyLifeStyle.Transient);
            IocManager.Register<CorsAuthorizationFilter>(DependencyLifeStyle.Transient);

            Configuration.ReplaceService(typeof(IAbpSession), () =>
            {
                IocManager.Register<IAbpSession, HicapSession>(DependencyLifeStyle.Transient);
            });
            Configuration.ReplaceService(typeof(IPrincipalAccessor), () =>
            {
                IocManager.Register<IPrincipalAccessor, HicapPrincipalAccessor>(DependencyLifeStyle.Transient);
            });
            Configuration.BackgroundJobs.UseHangfire();
        }
    }
}